import os
import shutil


def add_content(root_path, content):
    """
    功能介绍：为生成的 train.txt 文件和val.txt文件增加前缀
    :param root_path: train.txt,val.txt所在文件夹
    :param content: 前缀内容
    :return:
    """
    train_txt = os.path.join(root_path, 'train.txt')
    val_txt = os.path.join(root_path, 'val.txt')
    # add train.txt new content
    with open(train_txt, 'r') as f1:
        old_content = f1.readlines()
    with open(train_txt, 'w') as f1:
        for i in old_content:
            f1.write(os.path.join(content, i))
    # add val.txt new content
    with open(val_txt, 'r') as f2:
        old_content = f2.readlines()
    with open(val_txt, 'w') as f2:
        for j in old_content:
            f2.write(os.path.join(content, i))


def change_name(files_path, name):
    files_list = os.listdir(files_path)
    _, file_suffix = os.path.splitext(files_list[0])
    for i in range(len(files_list)):
        old_name = files_path + os.sep + files_list[i]
        new_name = files_path + os.sep + name + str(i + 1) + file_suffix
        os.rename(old_name, new_name)
        print(old_name, '======>', new_name)


if __name__ == "__main__":
    stored_path = r'D:\Develop\DataSet\2023-04-10-guarantee\remote-position\Images'
    change_name(stored_path, r'2023_06_14_remote_')
    # root_path = r"D:\Develop\DataSet\airport\yolov7-test"
    # add_content(root_path, "./data/airport")
